<template>
	<view class="content">
		<u--form labelPosition="left" labelWidth="70" :model="userInfo" :rules="rules" ref="form1">
			<u-form-item label="分配人员:" prop="username" @click="show = true">
				<u--input v-model="userInfo.username" disabled disabledColor="#ffffff" placeholder="请选择" suffixIcon="arrow-down">
				</u--input>
			</u-form-item>
			<u-form-item label="客户名称" prop="nickname">
				  <u--input
				    v-model="userInfo.nickname"
					readonly
				  ></u--input>
			</u-form-item>
		</u--form>
		<u-button @click="submit" color="#19BC9C">确认分配</u-button>
		<u-picker :show="show" :columns="adminlist" keyName="username" @cancel="show = false" @confirm="confirm"></u-picker>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				userInfo:{
					id: 0,
					nickname: '',
					username: '',
					adminid: 0
				},
				rules: {
					'content': {
						type: 'string',
						required: true,
						message: '请填写回访内容',
						trigger: ['blur', 'change']
					}
				},
				LoginUser: {},
				adminlist: [],
				show: false
			}
		},
		onLoad(options){
			this.userInfo.id = options.id ? options.id : 0
			this.userInfo.nickname = options.nickname ?  options.nickname : ''
			this.getAdmindata()
		},
		methods:{
			async getAdmindata(){
				let result = await this.$u.api.business.adminlist()
				if(result.code == 1){
					this.adminlist.push(result.data)
				}
			},
			// 回调参数为包含columnIndex、value、values
			confirm(e) {
				this.show = false
				this.userInfo.adminid = e.value[0].id
				this.userInfo.username = e.value[0].nickname
			},
			async submit(){
				let data = {
					adminid: this.userInfo.adminid,
					id: this.userInfo.id,
				}
				let result = await this.$u.api.business.highseaAllot(data)
				if(result.code == 1){
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
						complete() {
							uni.navigateTo({
								url: '/pages/business/highsea/index'
							});
						}
					})
				}  else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
		}
	}
</script>

<style>
	.content{
		/* width: 90%; */
		height: 100vh;
		/* margin: 0 auto; */
	}
</style>
